<template>
  <div class="app-container">
    <el-row :gutter="20">
      <el-col :span="show ? rowObj.T1 : rowObj.F1" :xs="show ? rowObj.T2 : rowObj.F2">
        <workSiteLeft ref="workSiteLeft" :show="show" @showLeft="showLeft" @queryVal="queryVal" />
      </el-col>

      <el-col :span="show ? rowObj.T3 : rowObj.F3" :xs="show ? rowObj.T4 : rowObj.F4">
        <div class="container-body">
          <el-form :inline="true" :model="queryParams" size="mini" style=" display: flex;justify-content: space-between;">
            <div>
              <el-button style="margin-right: 6px" size="mini" :icon="show ? 'el-icon-s-fold' : 'el-icon-s-unfold'" circle @click="showLeft(show)"></el-button>
              <el-form-item label="配方名称">
                <el-input v-model="queryParams.matchName" placeholder="配方名称" clearable @keyup.enter.native="handleQuery" />
              </el-form-item>

              <el-form-item>
                <el-button icon="el-icon-search" type="primary" @click="handleQuery()">查询</el-button>
              </el-form-item>
            </div>

            <el-form-item><el-button type="success" icon="el-icon-plus" @click="showEdit()">添加</el-button></el-form-item>
          </el-form>

          <el-table :data="dataList" v-loading="loading" fit border size="mini" highlight-current-row stripe>
            <el-table-column prop="matchName" label="配方名称" align="center" min-width="90px" fixed="left" show-overflow-tooltip></el-table-column>
            <el-table-column prop="asphaltTemperatureMin" label="温度下限" align="center" min-width="90px" show-overflow-tooltip></el-table-column>
            <el-table-column prop="asphaltTemperatureMax" label="温度上限" align="center" min-width="90px" show-overflow-tooltip></el-table-column>
            <el-table-column prop="asphaltAggregateRatioMin" label="油石比下限" align="center" min-width="90px" show-overflow-tooltip></el-table-column>
            <el-table-column prop="asphaltAggregateRatioMax" label="油石比上限" align="center" min-width="90px" show-overflow-tooltip></el-table-column>
            <el-table-column prop="gravel1Min" label="骨料1下限" align="center" min-width="90px" show-overflow-tooltip></el-table-column>
            <el-table-column prop="gravel1Max" label="骨料1上限" align="center" min-width="90px" show-overflow-tooltip></el-table-column>
            <el-table-column prop="gravel2Min" label="骨料2下限" align="center" min-width="90px" show-overflow-tooltip></el-table-column>
            <el-table-column prop="gravel2Max" label="骨料2上限" align="center" min-width="90px" show-overflow-tooltip></el-table-column>
            <el-table-column prop="gravel3Min" label="骨料3下限" align="center" min-width="90px" show-overflow-tooltip></el-table-column>
            <el-table-column prop="gravel3Max" label="骨料3上限" align="center" min-width="90px" show-overflow-tooltip></el-table-column>
            <el-table-column prop="gravel4Min" label="骨料4下限" align="center" min-width="90px" show-overflow-tooltip></el-table-column>
            <el-table-column prop="gravel4Max" label="骨料4上限" align="center" min-width="90px" show-overflow-tooltip></el-table-column>
            <el-table-column prop="gravel5Min" label="骨料5下限" align="center" min-width="90px" show-overflow-tooltip></el-table-column>
            <el-table-column prop="gravel5Max" label="骨料5上限" align="center" min-width="90px" show-overflow-tooltip></el-table-column>
            <el-table-column prop="gravel6Min" label="骨料6下限" align="center" min-width="90px" show-overflow-tooltip></el-table-column>
            <el-table-column prop="gravel6Max" label="骨料6上限" align="center" min-width="90px" show-overflow-tooltip></el-table-column>
            <el-table-column prop="powder1Min" label="粉料1下限" align="center" min-width="90px" show-overflow-tooltip></el-table-column>
            <el-table-column prop="powder1Max" label="粉料1上限" align="center" min-width="90px" show-overflow-tooltip></el-table-column>
            <el-table-column prop="powder2Min" label="粉料2下限" align="center" min-width="90px" show-overflow-tooltip></el-table-column>
            <el-table-column prop="powder2Max" label="粉料2上限" align="center" min-width="90px" show-overflow-tooltip></el-table-column>
            <el-table-column prop="powder3Min" label="粉料3下限" align="center" min-width="90px" show-overflow-tooltip></el-table-column>
            <el-table-column prop="powder3Max" label="粉料3上限" align="center" min-width="90px" show-overflow-tooltip></el-table-column>
            <el-table-column prop="recycledMaterialMin" label="再生料下限" align="center" min-width="90px" show-overflow-tooltip></el-table-column>
            <el-table-column prop="recycledMaterialMax" label="再生料上限" align="center" min-width="90px" show-overflow-tooltip></el-table-column>
            <el-table-column prop="asphaltMin" label="沥青下限" align="center" min-width="90px" show-overflow-tooltip></el-table-column>
            <el-table-column prop="asphaltMax" label="沥青上限" align="center" min-width="90px" show-overflow-tooltip></el-table-column>
            <el-table-column label="操作" align="center" width="95px" fixed="right">
              <template slot-scope="scope">
                <!-- v-if="$hasPermission('api:asphaltMatch:edit')" -->
                <el-link type="primary" @click="showEdit(scope.row.id)">编辑</el-link>
                <el-divider direction="vertical"></el-divider>
                <!-- v-if="$hasPermission('api:asphaltMatch:remove')" -->
                <el-link type="primary" @click="onDelete(scope.row.id)">删除</el-link>
              </template>
            </el-table-column>
          </el-table>
          <pagination class="fenye" v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList" />
        </div>
      </el-col>
    </el-row>

    <el-dialog :title="isAdd ? '添加生产配比' : '修改生产配比'"
               :visible.sync="visible" :close-on-click-modal="false" :close-on-press-escape="false" :before-close="doClose" width="50%" append-to-body>
      <el-form ref="editForm" lass="myForm" size="mini" :model="form" :inline="true" :rules="rules" label-width="130px" class="myForm" v-loading="loadingForm">
        <el-row>
          <el-col :span="24">
            <el-form-item label="配方名称" prop="matchName">
              <el-input v-model="form.matchName" placeholder="配方名称" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-form-item label="温度下限">
            <el-input type="number" v-model="form.asphaltTemperatureMin" placeholder="温度下限" >
              <template slot="suffix">%</template>
            </el-input>
          </el-form-item>
          <el-form-item label="温度上限">
            <el-input type="number" v-model="form.asphaltTemperatureMax" placeholder="温度上限" >
              <template slot="suffix">%</template>
            </el-input>
          </el-form-item>
        </el-row>
        <el-row>
          <el-form-item label="油石比下限">
            <el-input type="number" v-model="form.asphaltAggregateRatioMin" placeholder="油石比下限" >
              <template slot="suffix">%</template>
            </el-input>
          </el-form-item>
          <el-form-item label="油石比上限">
            <el-input type="number" v-model="form.asphaltAggregateRatioMax" placeholder="油石比上限" >
              <template slot="suffix">%</template>
            </el-input>
          </el-form-item>
        </el-row>
        <el-row>
          <el-form-item label="骨料1下限">
            <el-input type="number" v-model="form.gravel1Min" placeholder="骨料1下限" >
              <template slot="suffix">%</template>
            </el-input>
          </el-form-item>
          <el-form-item label="骨料1上限">
            <el-input type="number" v-model="form.gravel1Max" placeholder="骨料1上限" >
              <template slot="suffix">%</template>
            </el-input>
          </el-form-item>
        </el-row>
        <el-row>
          <el-form-item label="骨料2下限">
            <el-input type="number" v-model="form.gravel2Min" placeholder="骨料2下限" >
              <template slot="suffix">%</template>
            </el-input>
          </el-form-item>
          <el-form-item label="骨料2上限">
            <el-input type="number" v-model="form.gravel2Max" placeholder="骨料2上限" >
              <template slot="suffix">%</template>
            </el-input>
          </el-form-item>
        </el-row>
        <el-row>
          <el-form-item label="骨料3下限">
            <el-input type="number" v-model="form.gravel3Min" placeholder="骨料3下限" >
              <template slot="suffix">%</template>
            </el-input>
          </el-form-item>
          <el-form-item label="骨料3上限">
            <el-input type="number" v-model="form.gravel3Max" placeholder="骨料3上限" >
              <template slot="suffix">%</template>
            </el-input>
          </el-form-item>
        </el-row>
        <el-row>
          <el-form-item label="骨料4下限">
            <el-input type="number" v-model="form.gravel4Min" placeholder="骨料4下限" >
              <template slot="suffix">%</template>
            </el-input>
          </el-form-item>
          <el-form-item label="骨料4上限">
            <el-input type="number" v-model="form.gravel4Max" placeholder="骨料4上限" >
              <template slot="suffix">%</template>
            </el-input>
          </el-form-item>
        </el-row>
        <el-row>
          <el-form-item label="骨料5下限">
            <el-input type="number" v-model="form.gravel5Min" placeholder="骨料5下限" >
              <template slot="suffix">%</template>
            </el-input>
          </el-form-item>
          <el-form-item label="骨料5上限">
            <el-input type="number" v-model="form.gravel5Max" placeholder="骨料5上限" >
              <template slot="suffix">%</template>
            </el-input>
          </el-form-item>
        </el-row>
        <el-row>
          <el-form-item label="骨料6下限">
            <el-input type="number" v-model="form.gravel6Min" placeholder="骨料6下限" >
              <template slot="suffix">%</template>
            </el-input>
          </el-form-item>
          <el-form-item label="骨料6上限">
            <el-input type="number" v-model="form.gravel6Max" placeholder="骨料6上限" >
              <template slot="suffix">%</template>
            </el-input>
          </el-form-item>
        </el-row>
        <el-row>
          <el-form-item label="粉料1下限">
            <el-input type="number" v-model="form.powder1Min" placeholder="粉料1下限" >
              <template slot="suffix">%</template>
            </el-input>
          </el-form-item>
          <el-form-item label="粉料1上限">
            <el-input type="number" v-model="form.powder1Max" placeholder="粉料1上限" >
              <template slot="suffix">%</template>
            </el-input>
          </el-form-item>
        </el-row>
        <el-row>
          <el-form-item label="粉料2下限">
            <el-input type="number" v-model="form.powder2Min" placeholder="粉料2下限" >
              <template slot="suffix">%</template>
            </el-input>
          </el-form-item>
          <el-form-item label="粉料2上限">
            <el-input type="number" v-model="form.powder2Max" placeholder="粉料2上限" >
              <template slot="suffix">%</template>
            </el-input>
          </el-form-item>
        </el-row>
        <el-row>
          <el-form-item label="粉料3下限">
            <el-input type="number" v-model="form.powder3Min" placeholder="粉料3下限" >
              <template slot="suffix">%</template>
            </el-input>
          </el-form-item>
          <el-form-item label="粉料3上限">
            <el-input type="number" v-model="form.powder3Max" placeholder="粉料3上限" >
              <template slot="suffix">%</template>
            </el-input>
          </el-form-item>
        </el-row>
        <el-row>
          <el-form-item label="再生料下限">
            <el-input type="number" v-model="form.recycledMaterialMin" placeholder="再生料下限" >
              <template slot="suffix">%</template>
            </el-input>
          </el-form-item>
          <el-form-item label="再生料上限">
            <el-input type="number" v-model="form.recycledMaterialMax" placeholder="再生料上限" >
              <template slot="suffix">%</template>
            </el-input>
          </el-form-item>
        </el-row>
        <el-row>
          <el-form-item label="沥青下限">
            <el-input type="number" v-model="form.asphaltMin" placeholder="沥青下限" >
              <template slot="suffix">%</template>
            </el-input>
          </el-form-item>
          <el-form-item label="沥青上限">
            <el-input type="number" v-model="form.asphaltMax" placeholder="沥青上限" >
              <template slot="suffix">%</template>
            </el-input>
          </el-form-item>
        </el-row>
      </el-form>
      <span slot="footer">
        <el-button size="mini" @click="doClose">取消</el-button>
        <el-button type="primary" size="mini" @click="doSubmit" :loading="submitting">确定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { listZjNAsphaltMatch, getZjNAsphaltMatch,
  addZjNAsphaltMatch, updateZjNAsphaltMatch, delZjNAsphaltMatch }
  from "@/api/bitumenMixingStation/aspmatch/zjNAsphaltMatch";
import workSiteLeft from "@/views/components/workSiteLeft";

export default {
  name: "aspmatch",
  components: { workSiteLeft },
  data() {
    return {
      show: true,
      rowObj: {
        T1: 3,
        T2: 24,
        T3: 21,
        T4: 24,
        F1: 0,
        F2: 0,
        F3: 24,
        F4: 24,
      },
      submitting: true,
      visible: false,
      isAdd: true,
      dataList: [],
      loading: false,//表格加载
      loadingForm: false,//新增修改加载
      queryParams: {
        pageNum: 1,
        pageSize: 10,
      },
      total: 0,
      form: {},
      deptId: null,
      rules: {
        matchName: [{ required: true, message: '请填写配方名称', trigger: 'blur' }],
      },
    };
  },
  filters: {
  },
  created() {
    this.getList();
  },
  methods: {
    showLeft(show) {
      this.show = !show;
    },
    queryVal(val) {
      this.deptId = val.id;
      this.queryParams.id = val.id;
      this.handleQuery();
    },
    getList() {
      this.loading = true;
      listZjNAsphaltMatch(this.queryParams).then((res) => {
        this.dataList = res.rows;
        this.total = res.total;
        this.loading = false;
      });
    },
    getSearchParams() {
      const params = {};
      for (const key in this.queryParams) {
        if (key === "time") {
          const time = this.queryParams[key];
          if (time && time.length === 2) {
            params.startTime = time[0];
            params.endTime = time[1];
          }
        } else {
          params[key] = this.queryParams[key];
        }
      }
      return params;
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams = this.getSearchParams();
      this.queryParams.pageNum = 1;
      this.getList();
    },
    // 删除
    onDelete(id) {
      this.$confirm("此操作将删除该条数据, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
      .then(() => {
        delZjNAsphaltMatch(id).then((res) => {
          this.getList();
          this.$message({
            type: "success",
            message: "删除成功!",
          });
        });
      })
      .catch(() => {
        this.$message({
          type: "info",
          message: "已取消删除",
        });
      });
    },
    /* 关闭弹窗 */
    doClose() {
      this.visible = false;
    },
    /* 提交表单 */
    doSubmit() {
      this.$refs.editForm.validate((valid) => {
        if (valid) {
          if (this.isAdd) {
            // 新增
            // this.form.stationCode = "111";
            this.$set(this.form, 'stationCode', this.deptId);
            addZjNAsphaltMatch(this.form).then((res) => {
              this.$message.success("新增配比成功！");
              this.getList();
              this.visible = false;
              // this.btnLoading = false;
              // this.open = false;
            })
          } else {
            // 修改
            updateZjNAsphaltMatch(this.form).then((res) => {
              this.$message.success("修改配比成功！");
              this.getList();
              this.visible = false;
              // this.open = false;
            })
          }
        }
      });
    },
    showEdit(id) {
      this.isAdd = null == id || undefined == id;
      // 选择组织机构后允许添加
      if (!this.deptId && this.isAdd) {
        this.$message({
          type: "info",
          message: "请先选择左侧组织机构",
        });
        return false;
      }
      this.visible = true;
      this.loading = false;
      this.submitting = false;
      this.$nextTick(() => {
        if (this.isAdd) {
          this.form = {}
          this.$refs['editForm'].resetFields();
        } else {
          this.infoForm(id);
        }
      });
    },
    /* 获取数据 @param {*} id 数据主键 */
    infoForm(id) {
      this.loading = true;
      this.$refs['editForm'].clearValidate();
      getZjNAsphaltMatch(id).then((res) => {
        this.form = res.data;
        this.loading = false;
      }).catch(() => {
        this.form = {}
        this.loading = false;
      });
    },
  },
};
</script>

<style scoped>
.myForm>>>.el-input-number {
  width: 100%;
}
.myForm>>>.el-input__inner {
  text-align: left;
}
.myForm>>>.el-input-number {
  width: 100%;
}
.myForm>>>.el-input__inner {
  text-align: left;
}
.form-item-out {
  margin-bottom: 0px;
}
.colSplit {
  text-align: center;
  font-size: 16px;
}
.el-col {
  border: 1px solid transparent;
}
</style>

<style scoped lang="scss"></style>
